﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using EntityTools.Model;

using WAF.DAO;
using WAF.EntityFramework;

namespace EntityTools.Forms
{
    public partial class TableInfos : Form
    {
        private MainForm mainForm;

        public TableInfos(MainForm form)
        {
            InitializeComponent();

            mainForm = form;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            TableInfo tbInfo = null;
            TreeNode dbNode = mainForm.GetSelectedDbNode();

            string result = TableInfo.AddTableInfo(long.Parse(dbNode.Name), txtTableName.Text.Trim(), out tbInfo);

            if (result != null)
                MessageBox.Show(result);
            else
            {
                TreeNode node = new TreeNode();
                node.Name = tbInfo.Id.ToString();
                node.Text = tbInfo.TableName;
                dbNode.Nodes.Add(node);

                this.Close();
            }
        }
    }
}
